package com.zhou.combine.security.config.weblistener;

/**
 * RequestListener
 *
 * @author zhouxianfeng
 * @date 2021-3-23
 */

import lombok.extern.slf4j.Slf4j;

import javax.servlet.ServletContext;
import javax.servlet.ServletRequestEvent;
import javax.servlet.ServletRequestListener;
import javax.servlet.annotation.WebListener;

/**
 * 监听器
 *
 * @WebListener 此注解声明此类为listener，无需再进行配置，唯一注意的是，
 * 使用注解的方式声明Listener时，需要在main函数类上添加@ServletComponentScan(basePackages='此处写明类地址，格式为包名+类名')
 */
@WebListener
@Slf4j
public class RequestListener  implements ServletRequestListener {


    public static Integer count = 0;
    @Override
    public void requestDestroyed(ServletRequestEvent sre) {

    }

    @Override
    public void requestInitialized(ServletRequestEvent sre) {
        ServletContext aa = sre.getServletContext();
        log.info("访问次数为"+count);
        System.out.println("访问次数为"+count);
        count++;
    }

}

